package servlet.admin;

import entity.Admins;
import service.AdminsService;
import service.Impl.AdminsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;
import java.time.LocalDate;

@WebServlet(urlPatterns = "/admin/AdminEdit")
public class AdminEditServlet extends HttpServlet {
    private AdminsService service = new AdminsServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        Integer id = Integer.parseInt(req.getParameter("id"));
        String adminName = req.getParameter("adminName");
        String adminPwd = req.getParameter("adminPwd");
        String realName = req.getParameter("realName");
        String telephone = req.getParameter("telephone");
        String email = req.getParameter("email");
        String birthday = req.getParameter("birthday");
        String sex = req.getParameter("sex");
        String pic = req.getParameter("pic");
        String remark = req.getParameter("remark");
        Admins admin = new Admins();
        admin.setId(id);
        admin.setAdminName(adminName);
        admin.setAdminPwd(adminPwd);
        admin.setRealName(realName);
        admin.setTelephone(telephone);
        admin.setEmail(email);
        admin.setBirthday(Date.valueOf(birthday));
        admin.setSex(sex);
        admin.setPic(pic);
        admin.setRemark(remark);
        service.update(admin);
        resp.sendRedirect(req.getContextPath()+"/admin/AdminsList");
    }


}

